<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<% String paramId = request.getParameter("paramId"); %>
<% String actionItemId = request.getParameter("actionItemId"); %>
  <head>
    <title>参数决定动作添加页面</title>
    <script type="text/javascript">
    	var paramId = '<%=paramId %>';
    	var actionItemId = '<%=actionItemId %>';
    	var _init = function() {
    		var actionItemMap = pack.getActionItemMap();
    		var s = $("#actionItems");
    		$(s).html("");
    		if (actionItemMap) {
    			var paramDiv = $('div[id="action_param_'+ paramId +'"]');
    			var paramRelaDivs = $(paramDiv).find('div[id="param_action_relas"]').find("div");
    			var paramValue = $(paramDiv).find("select[id='paramValues']").find("option:selected").val();
    			var actionItems = actionItemMap.values();
    			$.each(actionItems, function(index, item) {
    				var itemId = item.getActionItemId();
    				var itemNumber;
					//p_条目ID
					if (itemIdMap.getValueFromKey(itemId) != "null") {
						itemNumber = packageContent.getItemNumberByItemId(itemIdMap.getValueFromKey(itemId));
					} else {
					//入库条目ID
						itemNumber = packageContent.getItemNumberByItemId(itemId);
					}
					var itemDesc = "(" + itemNumber + ") ";
    				if (itemId != actionItemId
    					&& !_ifActionRelaExists(paramValue, itemId, paramRelaDivs)) {
    					if (item.getDescription()) {
	    					itemDesc += item.getDescription();
	    				}
	    				var opt = $("<option>").text(itemDesc).val(itemId);
						s.append(opt);
    				}
    			});
    		} else {
    			$('#param_action_rela').html("未发现完整的动作条目，请先添加完整的动作条目再来设置！");
    		}
    	}
    	
    	var _ifActionRelaExists = function(paramValue, actionItemId, paramRelaDivs) {
    		var flag = false;
    		$.each(paramRelaDivs, function(index, paramRelaDiv) {
    			var currValue = $(paramRelaDiv).find("span[id='paramValue']").attr("val");
    			var currItemId = $(paramRelaDiv).find("span[id='actionItem']").attr("val");
    			if (currValue == paramValue && currItemId == actionItemId) {
    				flag = true;
    				return;
    			}
    		});
    		return flag;
    	}
    	
    	var _removeActionRela = function(obj) {
			$(obj).parent().parent().remove();
		}
    	var _saveActionRela = function() {
    		var paramDiv = $('div[id="action_param_'+ paramId +'"]');
    		var itemOptions = $("#actionItems option");
    		if (itemOptions.size() > 0) {
    			var paramRelaDiv = $(paramDiv).find('div[id="param_action_relas"]');
				var paramValue = $(paramDiv).find("select[id='paramValues']").find("option:selected").val();
				var paramValueDesc = $(paramDiv).find("select[id='paramValues']").find("option:selected").text();
				var actionItem = $("#actionItems option:selected").val();
				var actionItemDesc = $("#actionItems option:selected").text();
				var relaType = $("input:radio[name='relaType']:checked").val();
				var actionRela = '<div ><span id="paramValue" val="' + paramValue + '">【'+paramValueDesc+'】：</span>'
						+ '<span id="actionItem" val="' + actionItem + '">【' + actionItemDesc + '】</span>'
						+ '<span id="relaType" val="' + relaType + '">【' +ACTION.RELA_TYPE[relaType]+ '】</span>'
						+ '<a href="#"><img id="ation_param_rela_del" class="imgDelParam" title="删除参数决定条目" onclick="_removeActionRela(this)" align="right" /></a>'
						+ '</div>';
				    $(paramRelaDiv).show();
				$(paramRelaDiv).append($(actionRela));
    		}
    	}
    	var doSave = function() {
    		_saveActionRela();
    		doClose();
    	}
    	var doClose = function() {
    		$('#addParamActionRela').window("close");
    	}
    	_init();
    </script>
	<style type="text/css">
		.p_c_action_type {
			background-color:#EDF2F5;
			font-family:'新宋体';
			font-size:12px;
			font-weight:noml;
			overflow:hidden;
			height:100%;
		}
		.p_c_action_type input {
			margin-right:5px;
		}
	</style>
	</head>
	<body>
		<div id="paramActionRelaPanel" >
		<table width="100%" border="0" cellspacing="0" cellpadding="0" class="p_c_action_type">
		<tr>
		    <td valign="middle" >
		    	<div id="param_action_rela">
		        <select id="actionItems" style="width: 250px; margin-right: 10px;">
		          <option value="条目1">条目1</option>
		          <option value="条目2">条目2</option>
		        </select>
		        <input type="radio" name="relaType" value="Y" checked="checked">
		      		  必选
		        </input>
		        <input type="radio" name="relaType" value="C">
		      		  可选
		        </input>
		      </div>
		    </td>
		</tr>
		<tr>
		<td align="right">
			 <div class="btn_query">
		    <input type="button" class="btn-blue" onClick="doSave();" value="确定" />
		    <input type="button" class="btn-gray" onClick="doClose();" value="取消"/>
		  </div>
		</td>
		</tr>
	  </table>
		</div>
  </body>
</html>
